<extend name="Layout/ins_page" />
<block name="content">
	{:W('PageHeader/simple',array('name'=>'系统参数'))}
	<div class="layui-tab layui-tab-brief" >
		<ul class="layui-tab-title">
			<li>
				<a  href="{:U('index')}">基本设置</a>
			</li>
			<li>
				<a  href="{:U('weixin')}">微信设置</a>
			</li>
			<li class="layui-this">
				<a href="#">微信菜单</a>
			</li>
			<li>
				<a  href="{:U('config')}">系统参数</a>
			</li>
			<li>
				<a  href="{:U('push')}">推送设置</a>
			</li>
		</ul>
	</div>
	<select name="weixin_menu_list" id="weixin_menu_list" class="hidden">
		<option value="0">无</option>
		{:fill_option($weixin_menu_list)}
	</select>
	<div class="oprator-panel">
		<div class="col-16 x-select">
			<form id="form_search_weixin" name="form_search_weixin" method="post">
				<select class="layui-input" id="weixin_option" name="weixin_option" >
					{:fill_option($weixin_option,$weixin_option_id)}
				</select>
			</form>
		</div>
		<div class="split"></div>
		<a id="btn_release" class="btn">发布</a>
		<a id="btn_add_option" class="btn">新增应用</a>
		<a id="btn_add_menu"  class="btn">新增菜单</a>
		<a id="btn_save_menu"  class="btn">保存</a>
		<span class="l">|</span>
		<a id="btn_del_menu"  class="btn btn_del">删除</a>
	</div>

	<!-- 功能操作区域结束 -->
	<!-- 列表显示区域  -->
	<div class="sbu-frame">
		<div class="sub-frame">
			<div class="sub-sidebar gray">
				<form id="form_menu" name="form_menu" method="post">
					<input type="hidden" name="id" id="id" for="id">
					<php>
						echo $weixin_menu
					</php>
				</form>
			</div>
			<div class="sub-content gray">
				<form id="form_data_weixin" name="form_data_weixin" method="post" class="weixin">
					<input type="hidden" name="id" id="id">
					<div class="layui-sub-form-item">
						<label class="layui-form-label" for="name">菜单名称*：</label>
						<div class="layui-input-block">
							<input class="layui-input" type="text" id="name" name="name" check="required" info="请输入菜单名称">
						</div>
					</div>
					<div class="layui-sub-form-item">
						<label class="layui-form-label" for="val">事件选择*：</label>
						<div class="layui-input-block x-select">
							<select class="layui-input" name="type" id="type">
								<option value="click">点击推事件</option>
								<option value="view">跳转URL</option>
								<option value="scancode_push">扫码推事件</option>
								<option value="scancode_waitmsg">扫码推事件且弹出“消息接收中”提示框</option>
								<option value="pic_sysphoto">弹出系统拍照发图</option>
								<option value="pic_photo_or_album">弹出拍照或者相册发图</option>
								<option value="location_select">弹出地理位置选择器</option>
								<option value="media_id">下发消息（除文本消息）</option>
								<option value="view_limited">跳转图文消息URL</option>
							</select>
							<p>
								注：需要进行链接的事件为view事件
							</p>
						</div>
					</div>
					<div class="layui-sub-form-item ">
						<label class="layui-form-label" for="url">URL*：</label>
						<div class="layui-input-block">
							<input class="layui-input" type="text" id="url" name="url"  >
							<p>
								注：示例链接形式：index.php?m=&c=Task&a=folder&fid=all
							</p>
						</div>
					</div>

					<div class="layui-sub-form-item ">
						<label class="layui-form-label" for="key">Key*：</label>
						<div class="layui-input-block">
							<input class="layui-input" type="text" id="key" name="key" >
							<p>
								注：每个菜单需要有单独的key
							</p>
						</div>
					</div>
					<div class="layui-sub-form-item">
						<label class="layui-form-label" for="pid_name">父级*：</label>
						<div class="layui-input-block">
							<input name="pid_name" class="layui-input" id="pid_name" type="text" readonly="readonly" info="请选择父级" check="required"/>
							<input name="pid" id="pid" type="hidden" info="请选择父级" check="required" />
							<a class="add-on" onclick="select_weixin_pid()" type="button"> 选择 </a>
						</div>
					</div>

					<div class="layui-sub-form-item ">
						<label class="layui-form-label" for="sort">排序：</label>
						<div class="layui-input-block">
							<input class="layui-input" type="text" id="sort" name="sort" >
						</div>
					</div>
				</form>
				<p class="text-right">
					*一级菜单最多三个，二级菜单最多五个
				</p>
			</div>
		</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global', 'element'], function() {
			var $ = layui.jquery;
			//Tab的切换功能，切换事件监听等，需要依赖element模块
			$("#weixin_option").on('change', function() {
				$('#form_search_weixin').submit();
			});

			$(".tree_menu a").click(function() {
				$(".tree_menu a.active").removeClass("active");
				$(this).addClass("active");
				send_ajax("{:U('edit')}", "id=" + $(this).attr("node") + "&name=", function(data) {
					showdata_weixin(data);
				});
				return false;
			});

			$("#btn_save_menu").on('click', function() {
				send_form("form_data_weixin", "{:U('save_weixin_menu')}", "{:U('weixin_menu')}", function(ret) {
					if (ret.status) {
						layer.msg(ret.info, {
							time : 1200
						}, function() {
							location.reload(true);
						});
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});

			function showdata_weixin(result) {
				$("#form_data_weixin #id").val(result.data['id']);
				$("#form_data_weixin #name").val(result.data['name']);
				$("#form_data_weixin #url").val(result.data['url']);
				$("#form_data_weixin #key").val(result.data['key']);
				$("#form_data_weixin #pid").val(result.data['pid']);
				$("#form_data_weixin #type").val(result.data['type']);
				$("#form_data_weixin #sort").val(result.data['sort']);
				$("#pid_name").val($("#weixin_menu_list option[value='" + $("#pid").val() + "']").text());
				$("#opmode").val("edit");
			};

			$("#btn_add").on('click', function() {
				winopen("{:U('add')}", 560, 470);
			});

			$("#btn_add_menu").on('click', function() {
				winopen("{:U('add_menu')}", 560, 470);
			});

			$("#btn_release").on('click', function() {
				winopen("{:U('release')}", 560, 470);
			});

			$("#btn_add_option").on('click', function() {
				winopen("{:U('add_option')}", 560, 470);
			});
			$("#btn_del_menu").on('click', function() {
				if ($(".sub_left_menu a.active").parent().find(".tree_menu").html() != undefined) {
					ui_error("有子目录不能删除");
					return false;
				}
				layer.msg('确定要删除吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_data_weixin").serialize();
						send_ajax("{:U('del_menu')}", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});
		});
	</script>
</block>